crypto: add guards and adjust tests for BoringSSL#62883
crypto: add guards and adjust tests for BoringSSL#62883panva wants to merge 6 commits intonodejs:mainfrom
Conversation
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
|
Review requested:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #62883 +/- ##
=======================================
Coverage 89.62% 89.63%
=======================================
Files 706 706
Lines 219165 219197 +32
Branches 41989 41989
=======================================
+ Hits 196435 196474 +39
+ Misses 14621 14620 -1
+ Partials 8109 8103 -6
🚀 New features to boost your workflow:
|
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
| uint32_t len = args[0].As<Uint32>()->Value(); | ||
|
|
||
| auto data = DataPointer::SecureAlloc(len); | ||
| CHECK(data.isSecure()); |
There was a problem hiding this comment.
This CHECK was incorrect.
DataPointer::SecureAlloc wraps OPENSSL_secure_zalloc, which by design transparently falls back to a regular CRYPTO_zalloc when the secure heap is not available:
--secure-heap=0(the default), secure heap is never initialized, so everySecureAllocreturns a non-secure pointer.- Windows, secure-heap initialization is gated behind
#ifndef _WIN32inInitCryptoOnce, so it's never initialized there either. - BoringSSL does not implement
OPENSSL_secure_zallocat all; ncrypto falls back toOPENSSL_malloc+memsetand setssecure_=false. - OpenSSL with secure heap enabled but exhausted,
OPENSSL_secure_zallocsilently falls back to the regular heap.
The comment directly above SecureBuffer already documents this: "Without --secure-heap, OpenSSL's secure heap is disabled, in which case this has the same semantics as using OPENSSL_malloc." A non-secure fallback is an expected, documented outcome, so asserting isSecure() is not a valid invariant.
Why it didn't fire before
The CHECK only "passed" due to a bug in ncrypto::DataPointer::SecureAlloc, which unconditionally set secure_=true regardless of whether the returned pointer actually came from the secure heap. That bug is fixed in ncrypto (using CRYPTO_secure_allocated(ptr) to track actual use of secure heap), which in turn exposed the CHECK as unsound on default cli options, on Windows, and made the process crash on BoringSSL builds where secure_ was already correctly false.
Impact
Paired with the ncrypto fix randomUUID() (the only caller of secureBuffer) continues to work exactly as before; it just no longer aborts on BoringSSL / when the ncrypto provenance fix is in place.
This reduces the number of patches needed to make Node.js compile and test crypto/webcrypto when running linked against BoringSSL (date below)
Some of the patches have been adapted from these sources:
ncrypto changes are already in / from https://github.com/nodejs/ncrypto/blob/88555cc07e8ffcfdbbab779e86cc6225317ee6ae/include/ncrypto.h#L332-L343 / https://github.com/nodejs/ncrypto/blob/88555cc07e8ffcfdbbab779e86cc6225317ee6ae/src/ncrypto.cpp#L3240-L3248